package edu.gyc.objecthomework; /**

File name: GradesGraph.java

Class for a GradesGraph.

An object of this class has these attributes
Number of each letter grade, A, B, C, D, and F.

Public methods:
Set the number of each grade individually or as a group.
Read the number of each grade individually or as a group.
Return the number of each grade.
Return the total number of grades.
Return the percent of each grade.
(a whole number from 0 to 100).
Display a graph of the number of each grade (by printing
a lines of asterisks proportional to number of grades).

Preconditions:
For set methods: the GradesGraph object has been created.
For read & return methods: values have been assigned to the
data members.

Postconditions:
Set methods: one or all grade counts have assigned a value.
Read methods: values displayed for one or all data members.
Graph method: lines of asterisks proportional to the number
of each grade are displayed.

Written by: Lew Rakocy
email address: Lrakocy@devrycols.edu
Date: 8/20/2000
Last changed: 
Updated for fourth edition by Brian Durney, November 2004

*/

import java.util.*;

public class GradesGraph
{
    private int Acount;
    private int Bcount;
    private int Ccount;
    private int Dcount;
    private int Fcount;
    private int asteriskCount;

    /**
       
    Methods to set data members
       
    */

    //Interactively assign values to all data members
    public void readInput()
    {
        Scanner keyboard = new Scanner(System.in);

        System.out.println("How many A's?");
        Acount = keyboard.nextInt();
        while (Acount < 0)
        {
            System.out.println("Number of grades cannot be negative.");
            System.out.println("Reenter number of A's: ");
            Acount = keyboard.nextInt();
        }

        System.out.println("How many B's?");
        Bcount = keyboard.nextInt();
        while (Bcount < 0)
        {
            System.out.println("Number of grades cannot be negative.");
            System.out.println("Reenter number of B's: ");
            Bcount = keyboard.nextInt();
        }

        System.out.println("How many C's?");
        Ccount = keyboard.nextInt();
        while (Ccount < 0)
        {
            System.out.println("Number of grades cannot be negative.");
            System.out.println("Reenter number of C's: ");
            Ccount = keyboard.nextInt();
        }

        System.out.println("How many D's?");
        Dcount = keyboard.nextInt();
        while (Dcount < 0)
        {
            System.out.println("Number of grades cannot be negative.");
            System.out.println("Reenter number of D's: ");
            Dcount = keyboard.nextInt();
        }


        System.out.println("How many F's?");
        Fcount = keyboard.nextInt();
        while (Fcount < 0)
        {
            System.out.println("Number of grades cannot be negative.");
            System.out.println("Reenter number of F's: ");
            Fcount = keyboard.nextInt();
        }
    }

    //Set values of all data members non-interactively
    public void set(int newAcount,
                    int newBcount,
                    int newCcount,
                    int newDcount,
                    int newFcount)
    {
        if (newAcount >= 0)
            Acount = newAcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }

        if (newBcount >= 0)
            Bcount = newBcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }

        if (newCcount >= 0)
            Ccount = newCcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }

        if (newDcount >= 0)
            Dcount = newDcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }

        if (newFcount >= 0)
            Fcount = newFcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }

    }

    //Set individual data member's value
    public void setAcount(int newAcount)
    {
        if (newAcount >= 0)
            Acount = newAcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }
    }

    public void setBcount(int newBcount)
    {
        if (newBcount >= 0)
            Bcount = newBcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }
    }

    public void setCcount(int newCcount)
    {
        if (newCcount >= 0)
            Ccount = newCcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }
    }

    public void setDcount(int newDcount)
    {
        if (newDcount >= 0)
            Dcount = newDcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }
    }

    public void setFcount(int newFcount)
    {
        if (newFcount >= 0)
            Fcount = newFcount;
        else
        {
            System.out.println
                ("ERROR: number of grades cannot be negative.");
            System.exit(0);
        }
    }

    /**
       
    Methods to write (display) data members
       
    */

    public void writeOutput()
    {
        System.out.println("Number of A's = " + Acount);
        System.out.println("Number of B's = " + Bcount);
        System.out.println("Number of C's = " + Ccount);
        System.out.println("Number of D's = " + Dcount);
        System.out.println("Number of F's = " + Fcount);
    }

    public void writeAcount()
    {
        System.out.println("Number of A's = " + Acount);
    }

    public void writeBcount()
    {
        System.out.println("Number of B's = " + Bcount);
    }

    public void writeCcount()
    {
        System.out.println("Number of C's = " + Ccount);
    }

    public void writeDcount()
    {
        System.out.println("Number of D's = " + Dcount);
    }

    public void writeFcount()
    {
        System.out.println("Number of F's = " + Fcount);
    }

    /**
       
    Methods to return values of data members
       
    */

    public int getAcount()
    {
        return Acount;
    }

    public int getBcount()
    {
        return Bcount;
    }

    public int getCcount()
    {
        return Ccount;
    }

    public int getDcount()
    {
        return Dcount;
    }

    public int getFcount()
    {
        return Fcount;
    }

    /**
       
    Method to return total number of grades
       
    */

    public int getTotalNumberOfGrades()
    {
        return (Acount + Bcount + Ccount + Dcount + Fcount);
    }

    /**
       
    Method to return percentages of each grade
       
    */

    public int getPercentA()
    {
        return (int)((float)Acount/this.getTotalNumberOfGrades() * 100
                     + 0.5);// rounding calculation
    }

    public int getPercentB()
    {
        return (int)((float)Bcount/this.getTotalNumberOfGrades() * 100
                     + 0.5);// rounding calculation
    }

    public int getPercentC()
    {
        return (int)((float)Ccount/this.getTotalNumberOfGrades() * 100
                     + 0.5);// rounding calculation
    }

    public int getPercentD()
    {
        return (int)((float)Dcount/this.getTotalNumberOfGrades() * 100
                     + 0.5);// rounding calculation
    }

    public int getPercentF()
    {
        return (int)((float)Fcount/this.getTotalNumberOfGrades() * 100
                     + 0.5);// rounding calculation
    }

    /**
       
    Method to graph grade counts by printing lines of asterisks
       
    */

    public void draw()
    {
        //Draw scale
        System.out.println("2   10   20   30   40   50"
                           + "   60   70   80   90   100");
        System.out.println("|   |    |    |    |    |"
                           + "    |    |    |    |    |");
        System.out.println("*************************"
                           + "*************************");

        //Print row for each grade, from A to F
        //Each asterisk is 2%, so the number of asterisks
        //to print is the percent of a grade divided by 2.
        // (since the fractional part is either 0
        // or 0.5, just truncate)

        for(asteriskCount = 1;
            asteriskCount <= getPercentA()/2;
            asteriskCount++)
        {
            System.out.print("*");
        }
        System.out.println(" A");

        for(asteriskCount = 1;
            asteriskCount <= getPercentB()/2;
            asteriskCount++)
        {
            System.out.print("*");
        }
        System.out.println(" B");

        for(asteriskCount = 1;
            asteriskCount <= getPercentC()/2;
            asteriskCount++)
        {
            System.out.print("*");
        }
        System.out.println(" C");

        for(asteriskCount = 1;
            asteriskCount <= getPercentD()/2;
            asteriskCount++)
        {
            System.out.print("*");
        }
        System.out.println(" D");

        for(asteriskCount = 1;
            asteriskCount <= getPercentF()/2;
            asteriskCount++)
        {
            System.out.print("*");
        }
        System.out.println(" F");

    } // end main
}
